package com.cq.school.repository;

import com.cq.school.entity.Article;
import com.cq.school.entity.School;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: huke
 * Date: 13-12-4
 * Time: 下午9:38
 * To change this template use File | Settings | File Templates.
 */
public interface SchoolDao extends PagingAndSortingRepository<School, Long>, JpaSpecificationExecutor<School> {
    Page<Article> findByNameLike(String  name, Pageable pageRequest);

    @Modifying
    @Query("update School a set a.recommend = a.recommend+?2 where a.id = ?1")
    void recommendSchool(long schoolId,int recomm);
    @Modifying
    @Query("update School a set a.recommend = a.recommend-?2 where a.id = ?1")
    void cancelRecommen(long schoolId,int recomm);
    @Query(value = "SELECT * FROM school WHERE recommend & ?1 = ?1 order by update_time desc limit ?2", nativeQuery = true)
    List<School>  listRecommenSchool(int recommon,int size);
}
